# coding=utf-8
# 代码文件：chapter1/ch1.14.2-2.py

import datetime as dt

f_name = 'data/test1.txt'


def read_date_from_file(filename):
    try:
        with open(filename) as file:
            in_date = file.read()

        in_date = in_date.strip()
        date = dt.datetime.strptime(in_date, '%Y-%m-%d')
        return date
    except ValueError:
        print('处理ValueError异常')
    except OSError:
        print('处理OSError异常')


if __name__ == '__main__':
    date = read_date_from_file(f_name)
    print('日期 = {0}'.format(date))
